<template>
  <div>
    <tableComponents :pagination="{currentPage,pageSize,total:list.all_num}" @handleCurrentChange="handleCurrentChange"
        @handleSizeChange="handleSizeChange" :isShow="false" :isHaveExport="false" @toAdd="showEditDialog">
      <template v-slot:table>
        <el-table ref="multipleTable" :data="list.data" v-loading="loading" header-row-class-name="head_color" stripe tooltip-effect="dark"
            style="width: 99.9%" @selection-change="handleSelectionChange">
          <el-table-column type="selection" class="tc" width="35"></el-table-column>

          <el-table-column label="封面图" min-width="80">
            <template slot-scope="scope">
              <div class="img_bor_tx">
                <img :src="$fnc.getImgUrl(scope.row.piclink) " />
              </div>
            </template>
          </el-table-column>

          <el-table-column label="店铺信息" min-width="160">
            <template slot-scope="scope">
              <div class="tab_div">
                <div>
                  <span>店铺名称：</span>
                  <span>{{scope.row.title || '----'}}</span>
                </div>
                <div>
                  <span>联系姓名：</span>
                  <span>{{scope.row.name ||'---'}}</span>
                </div>
                <div>
                  <span>联系电话：</span>
                  <span>{{scope.row.tel ||'---'}}</span>
                </div>
              </div>

            </template>
          </el-table-column>

          <el-table-column label="店长头像" min-width="80">
            <template slot-scope="scope">
              <div class="img_bor_tx">
                <img :src="$fnc.getImgUrl(scope.row.avatar)" alt />
              </div>
            </template>
          </el-table-column>

          <el-table-column label="店长信息" min-width="160">
            <template slot-scope="scope">
              <div class="tab_div">
                <div>
                  <span>用户昵称：</span>
                  <span>{{scope.row.nickname || '----'}}</span>
                </div>
                <div>
                  <span>会员账号：</span>
                  <span>{{scope.row.username ||'---'}}</span>
                </div>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="地址" min-width="160">
            <template slot-scope="scope">
              <div class="tab_div">
                <div>
                  <span>地区：</span>
                  <span>{{ (scope.row.province || '')+(scope.row.city|| '')+(scope.row.area|| '')}}</span>
                </div>
                <div>
                  <span>地区：</span>
                  <span>{{scope.row.add ||'---'}}</span>
                </div>
                <div>
                  <span>经纬度：</span>
                  <span>{{scope.row.latitude+scope.row.longitude}}</span>
                </div>
              </div>
            </template>
          </el-table-column>

          <el-table-column label="操作" min-width="200">
            <template slot-scope="scope">
              <el-button :loading="$store.state.isLoading" type="primary" size="mini" @click="showEditDialog(scope.row.id)">编辑</el-button>
              <el-button @click="edit_price_btn(scope.row.id)" :loading="$store.state.isLoading" size="mini">设置预约时间</el-button>
              <el-button :loading="$store.state.isLoading" size="mini" @click="deleteNew(scope.$index, scope.row.id)" type="danger">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
      </template>
      <template v-slot:footerLeft>
        <a class="aBtn aBtn_1 aBtn_lan2" @click="delSelection">删除</a>
      </template>
    </tableComponents>

    <StoreEdit @parent="reload" :show.sync="myshow" :editId="editId" :clickNum="clickNum"></StoreEdit>

    <el-dialog :close-on-click-modal="false" title="设置预约时间" class="rich_dia" center width="800px" :append-to-body="true" :visible.sync="dia_time">
      <reserveTime :editId="editId" @closeDialog="getCloseDialog"></reserveTime>
    </el-dialog>
  </div>
</template>
<script>
import StoreEdit from "@/components/reserve/store_edit.vue";
import reserveTime from "@/components/currency/reserve_time.vue";

export default {
  data () {
    return {
      myshow: false,
      loading: false,
      list: [],
      allPage: 0,
      allNum: 0,
      pageSize: 10,
      currentPage: 1,
      editId: "",
      multipleSelection: "",
      arr: [],
      visible: false,
      clickNum: 1,
      updataIndex: "",
      dia_time: false,
      price_shopid: null
    };
  },
  components: {
    StoreEdit,
    reserveTime
  },
  methods: {
    getCloseDialog () {
      this.dia_time = false;
    },
    edit_price_btn (id) {
      this.editId = id;
      this.dia_time = true;
    },
    imgError (item) {
      if (!item) {
        return require("../../assets/img/default_head.png");
      }
      if (item.indexOf("http") >= 0) {
        return item;
      } else {
        return "/api/" + item;
      }
    },
    getNewsAll (page, page_size) {
      this.loading = true;
      page = page || 1;
      page_size = page_size || 10;
      var data = { page: page, page_size: page_size };
      this.$api.getUser.get_reserve_store_lists(data).then(res => {
        if (res.data.code == 200) {
          this.list = res.data.result;
        }
        this.loading = false;
      });
    },
    handleSizeChange (val) {
      this.getNewsAll("", val);
      this.pageSize = val;
    },
    handleCurrentChange (val) {
      this.currentPage = val;
      this.getNewsAll(val, this.pageSize);
    },

    handleSelectionChange (val) {
      //多选框赋值
      this.multipleSelection = val;
    },
    delSelection () {
      //删除
      this.$swal({
        title: "您确定要删除这条信息吗",
        text: "删除后将无法恢复，请谨慎操作！",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "是的，我要删除",
        cancelButtonText: "容我三思"
      }).then(willDelete => {
        if (willDelete.value) {
          var str = "";
          for (var i in this.multipleSelection) {
            str += this.multipleSelection[i].id + "@";
          }
          str = str.slice(0, -1);
          var data = { id_str: str };
          this.$api.getUser.reserve_store_del(data).then(res => {
            if (res.data.code == 200) {
              this.getNewsAll();
            }
          });
        }
      });
    },
    deleteNew (index, id) {
      this.$swal({
        title: "您确定要删除这条信息吗",
        text: "删除后将无法恢复，请谨慎操作！",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "是的，我要删除",
        cancelButtonText: "容我三思"
      }).then(willDelete => {
        if (willDelete.value) {
          var data = { id_str: id };
          this.$api.getUser.reserve_store_del(data).then(res => {
            if (res.data.code == 200) {
              this.$swal("删除成功！", "您已经删除了这条信息。", "success");
              this.getNewsAll();
            } else {
              this.$swal("删除失败！", "出错啦！", "success");
            }
          });
        }
      });
    },
    showEditDialog (id) {
      this.myshow = true;
      this.editId = id;
      this.clickNum++;
    },
    reload (id) {
      this.getNewsAll();
    }
  },
  created () {
    this.getNewsAll();
  }
};
</script>
